package org.hxyjs.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Advertisers;
import org.hxyjs.entity.Advertisers;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.AdvertisersService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller
@RequestMapping("/advertisersController")
public class AdvertisersController {
	@Resource
	AdvertisersService advertisersService;
	@RequiresPermissions("advertisers:getAll")
	@RequestMapping("/getAllAdvertisers")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Advertisers> getAllAdvertisers() throws Exception {
    	System.out.println("查询全部广告商");
		return advertisersService.getAllAdvertiserss();
    }

	@RequestMapping("/deleteAdvertisersByAdno/{adno}")
	@ResponseBody
    public DTO<Advertisers> deleteAdvertisersByAdno(@PathVariable("adno") String adno) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(adno+"删除广告商");
    	return advertisersService.deleteAdvertisersByAdno(adno);
    }

	@RequestMapping("/updateAdvertisersByAdno")
	@ResponseBody
	public DTO<Advertisers> updateAdvertisersByAdno(@RequestBody Advertisers advertisers) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改广告商");
		return advertisersService.updateAdvertisersByAdno(advertisers);
	}


	@RequestMapping("/addAdvertisers")
	@ResponseBody
	public DTO<Advertisers> addAdvertisers(@RequestBody Advertisers advertisers) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加广告商");
		System.out.println(advertisers);
 		return advertisersService.addAdvertisers(advertisers);
	}
	@RequestMapping("/getAdvertisersByPage")
	@ResponseBody
	public DTO<Advertisers> getAdvertisersByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页广告商");
		return advertisersService.getAdvertisersByPage(pageInfo);
	}

}